define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'qrcode', 'layer', 'upload'], function ($, undefined, Backend, Table, Form, qrcode, layer, Upload) {
 
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    ajaxOperate : ['edit']
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                pk: 'id',
                sortName: 'id',
                queryParams:function(params) {
                    // 要显示的字段
                    // params.fields = '';
                    // // 要关联的拓展信息
                    params.extra = 'user_info,customer_info';
                    return params;
                },
                // search:true,
                // commonSearch: true,
                // searchFormVisible: false,
                columns: [
                    [
                        // {field: 'state', checkbox: true, },
                        {field: 'id', title: 'ID',operate:false},
                        {field: 'order_sn', title: '订单号',operate: false},
                        {field: 'user_info.nickname', title: '所属用户',align:'left'},
                        {field: 'customer_info.customer_realname', title: '所属客户经理',align:'left'},
                        {field: 'result_name', title: '当前状态',align:'left'},
                        {field: 'create_time', title: '创建时间', formatter: Table.api.formatter.datetime,operate:false},
                        {field: 'update_time', title: '更新时间', formatter: Table.api.formatter.datetime,operate:false},
                        {field: 'operate', title: __('Operate'), events: Controller.api.events.operate, formatter: Controller.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter:{
                operate: function (value, row, index) {
                    return '<a href="javascript:;" class="btn btn-success btn-result btn-xs"><i class="fa fa-pencil"></i> 处理</a>';
                    //return Table.api.formatter.operate(value, row, index, $("#table"));
                }
            },
            events:{
                operate: $.extend({
                    'click .btn-result': function (e, value, row, index) {
                        e.stopPropagation();
                        var options = $(this).closest('table').bootstrapTable('getOptions');
                        // if(!options.editUri) return false;
                        // var editUri = options.editUri += "/ids/" + row[options.pk];
                        // if(options.extend.ajaxOperate && $.inArray("edit", options.extend.ajaxOperate) !== -1) {
                        //     Fast.api.open(editUri, __('Edit'));
                        // } else {
                        //     window.location.href = options.editUri;
                        // }

                        Fast.api.ajax({
                            url : '/product/admin.order_complain/do_result',
                            data : {
                                id : row[options.pk]
                            }
                        }, function () {
                            Toastr.success(__('Operation completed'));
                            table.bootstrapTable('refresh');
                        });

                    }
                }, Table.api.events.operate)
            }
        }
    }
    return Controller;
});